#include "show.h"
#include "info.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

Mesg send_mesg1;
Mesg *send_mesg = &send_mesg1;

Mesg *client_login(void)
{
	memset(send_mesg,0,sizeof(Mesg));
	Mesg *login_mesg = send_mesg;
	printf("***欢迎使用飞扬集团员工管理系统***\n");
	printf("请登录\n");
	printf("工号：");
	scanf("%s",login_mesg->work_num);
	printf("密码：");
	scanf("%s",login_mesg->passwd);
	login_mesg->cmd = 0;
	return login_mesg;
}


void admin_show(void)
{
	printf("***欢迎进入管理员模式***\n");
	printf("\n");
	printf("--------使用方法----------\n");
	printf("1.增加用户：adduser\n");
	printf("2.删除用户：deluser\n");
	printf("3.修改用户：chuser\n");
	printf("4.查询用户：find\n");
	printf("5.退出系统：quit\n");
	printf("--------------------------\n");	
}


void user_show(void)
{
	printf("***欢迎进入用户模式***\n");
	printf("\n");
	printf("--------使用方法----------\n");
	printf("1.查询我的信息：showinfo\n");
	printf("2.修改登录密码：chpasswd\n");
	printf("3.退出程序:quit\n");
	printf("--------------------------\n");	
}


Mesg *admin_mode(Mesg *admin_info)
{
	memset(send_mesg,0,sizeof(Mesg));
	Mesg *admin_send = send_mesg;
	admin_send->type = 0;
	while(1)
	{
		printf("admin>");
		char cmd[10];
		scanf("%s",cmd);
		if(strcmp(cmd,"adduser") == 0)
		{
			admin_send->cmd = 1;
			printf("请输入名字：");
			scanf("%s",admin_send->name);

			printf("请输入工号：");
			scanf("%s",admin_send->work_num);

			printf("请输入密码：");
			scanf("%s",admin_send->passwd);

			printf("请输入职位：");
			scanf("%s",admin_send->post);

			printf("请输入部门：");
			scanf("%s",admin_send->branch);

			printf("请输入工资：");
			scanf("%d",&admin_send->pay);
			break;
		}	
		else if(strcmp(cmd,"deluser") == 0)
		{
			printf("请输入要删除的工号：");
			scanf("%s",admin_send->work_num);
			admin_send->cmd = 5;
			break;
		}
		else if(strcmp(cmd,"chuser") == 0)
		{
			admin_send->cmd = 4;
			printf("请输入要修改的工号：");
			scanf("%s",admin_send->work_num);
			
		//	write(sockfd,admin_send,sizeof(Mesg));
			
			printf("更正姓名：");
			scanf("%s",admin_send->name);
			
			printf("更正密码：");
			scanf("%s",admin_send->passwd);

			printf("更正职位：");
			scanf("%s",admin_send->post);

			printf("更正部门：");
			scanf("%s",admin_send->branch);

			printf("更正工资：");
			scanf("%d",&admin_send->pay);
			
			
			break;

		}	
		else if(strcmp(cmd,"find") == 0)
		{
			admin_send->cmd = 2;
			printf("请输入要查看的工号：");
			scanf("%s",admin_send->work_num);
			break;
		}	
		else if(strcmp(cmd,"quit") == 0)
		{
			exit(0);
			break;
		}
		else
		{
			printf("你输入的有误！请重新输入\n");
		}
	}

	return admin_send;
}


Mesg *user_mode(Mesg *user_info)
{
	memset(send_mesg,0,sizeof(Mesg));
	Mesg *user_send = send_mesg;
	//printf("work_num:%s",user_info->work_num);
	user_send->type = 1;
	while(1)
	{
		printf("user>");
		char cmd[10];
		scanf("%s",cmd);
		if(strcmp(cmd,"showinfo") == 0)
		{
			user_send->cmd = 2;
			strcpy(user_send->work_num,user_info->work_num);
			break;
		}
		else if(strcmp(cmd,"chpasswd") == 0)
		{
			user_send->cmd = 3;
			char pw[10] ;
			printf("请输入你的新密码：");
			scanf("%s",pw);
			strcpy(user_send->passwd,pw);
			strcpy(user_send->work_num,user_info->work_num);
			break;
		}
		else if(strcmp(cmd,"quit") == 0)
		{
				exit(0);
		}
		else
		{
			printf("输入错了，请重新输入！\n");
		}
	}
	return user_send;

}
